package com.tianyu.service.mqtt.model.enums;

import lombok.extern.slf4j.Slf4j;

import java.util.Arrays;

/**
 * @author swyan
 * @version 1.1
 * @date 2022/6/1
 */
@Slf4j
public enum EventsMethodEnum {

    FLIGHT_TASK_PROGRESS("flighttask_progress", "flighttaskProgress"),
    FILE_UPLOAD_CALLBACK("file_upload_callback", "fileUploadCallback"),


    UNKNOWN("Unknown", "unknown");

    private final String method;

    private final String messageType;

    EventsMethodEnum(String method, String messageType) {
        this.method = method;
        this.messageType = messageType;
    }

    public String getMethod() {
        return method;
    }

    public String getMessageType() {
        return messageType;
    }

    public static EventsMethodEnum find(String method) {

        if (method == null || "".equals(method)){
            log.warn(method);
            return UNKNOWN;
        }
        log.info(method);
        return Arrays.stream(EventsMethodEnum.values())
                .filter(methodEnum -> methodEnum.method.equals(method))
                .findAny()
                .orElse(UNKNOWN);
    }
}
